package com.wanli.storemobile.base;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.Arrays;
import java.util.List;

/**
 * Time: 2019/8/1
 * Author: ZF
 * Description:
 */

public class Adapter_ViewPager_Fragment extends FragmentPagerAdapter {

    private List<BaseFragment> mFragments;
    private List<String> titlesList;


    public Adapter_ViewPager_Fragment(FragmentManager fm) {
        super(fm);
    }

    public Adapter_ViewPager_Fragment(FragmentManager fm, @Nullable List<BaseFragment> mFragments, @Nullable List<String> titlesList) {
        super(fm);
        this.mFragments = mFragments;
        this.titlesList = titlesList;
    }

    public Adapter_ViewPager_Fragment(FragmentManager fm, @NonNull List<BaseFragment> mFragments, @NonNull String[] titlesList) {
        super(fm);
        this.mFragments = mFragments;
        this.titlesList = Arrays.asList(titlesList);
    }

    public void setDataList(List<BaseFragment> mFragments, List<String> titlesList) {
        this.mFragments = mFragments;
        this.titlesList = titlesList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {

        if (titlesList == null || titlesList.size() == 0 || mFragments == null || mFragments.size() == 0) {
            return 0;
        }
        if (titlesList.size() != mFragments.size()) {
            return 0;
        }
        return mFragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titlesList.get(position);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }
}



